import { useUser } from '@/hooks/useUser'
import { useSystemInfo } from '@/hooks/useSystemInfo'
import { useLocation } from 'react-router-dom'
import { useEffect } from 'react'
import { quitLogin } from '@/utils/common'
import { useCompanyInfo } from '@/components/Header/hook'
// import '@/i18n/index'

const useAppHook = () => {
	let { userInfo, reFetch } = useUser()
	let { systemInfo, reFetch: systemReFetch } = useSystemInfo()
	const NotShowMenu = ['/set', '/set/profile', '/set/password', '/set/pin', '/set/ip', '/configuration']
	/**实时随路由改变得到的路由地址 */
	let { pathname } = useLocation()
	useEffect(() => {
		//多少秒后页面不操作，退出
		if (userInfo && userInfo.expiredIn && window.__userBehavior__) {
			let time = userInfo.expiredIn
			// recordUserOperationBehavior(time)
			window.__userBehavior__.recordUserOperationBehavior({
				expired_in: time, //token有效时长，单位：秒，从登录得用户session中获取
				onQuit: () => {
					//到期执行得回调函数，如果需要退出，需要调用各业务得退出逻辑
					quitLogin()
				},
			})
		}
	}, [userInfo])
	/**是否展示菜单部分 ，目前个人设置页面不展示菜单*/
	let isShowMenu = NotShowMenu.indexOf(pathname) > -1 ? false : true
	const { companyInfo } = useCompanyInfo()
	window.document.title = companyInfo.systemName
	return {
		/**用户信息 */
		user: userInfo,
		/**系统信息 */
		system: systemInfo,
		/**重新刷新用户信息 */
		reLoadUser: reFetch,
		/**重新刷新系统信息 */
		reLoadSystem: systemReFetch,
		/**是否展示菜单部分 */
		isShowMenu,
		/**获取当前路由 */
		pathname,
	}
}
export default useAppHook
